package com.ss.android.download;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import com.bytedance.common.utility.Logger;
import com.ss.android.common.download.DownloadAdapterProxy;

public class DownloadReceiver extends BroadcastReceiver {
    private t a;

    public DownloadReceiver() {

        this.a = null;
    }

    public void onReceive(Context arg5, Intent arg6) {
        if (arg5 != null && arg6 != null) {
            try {
                if (!android.support.design.a.u(arg5)) {
                    return;
                }
                if (!android.support.design.a.p()) {
                    return;
                }
                String v0_1 = arg6.getAction();
                if (TextUtils.isEmpty(((CharSequence) v0_1))) {
                    return;
                }

                if ("android.intent.action.BOOT_COMPLETED".equals(v0_1)) {
                    return;
                }

                if (this.a == null) {
                    this.a = p.a(arg5);
                }

                if (v0_1.equals("android.intent.action.BOOT_COMPLETED")) {
                    if (com.ss.android.download.aa.d) {
                        Log.v("SsDownloadManager", "Received broadcast intent for android.intent.action.BOOT_COMPLETED");
                    }

                    DownloadService.a(arg5);
                    return;
                }

                if (v0_1.equals("android.intent.action.MEDIA_MOUNTED")) {
                    if (com.ss.android.download.aa.d) {
                        Log.v("SsDownloadManager", "Received broadcast intent for android.intent.action.MEDIA_MOUNTED");
                    }

                    DownloadService.a(arg5);
                    return;
                }

                if (v0_1.equals("android.net.conn.CONNECTIVITY_CHANGE")) {
                    ConnectivityManager connectivityManager = (ConnectivityManager) arg5.getSystemService(Context.CONNECTIVITY_SERVICE);
                    NetworkInfo v0_2 = connectivityManager.getActiveNetworkInfo();
                    if (v0_2 == null) {
                        return;
                    }

                    if (!v0_2.isConnected()) {
                        return;
                    }

                    DownloadService.a(arg5);
                    if (android.support.design.a.o() == null) {
                        return;
                    }

                    android.support.design.a.o();
                    return;
                }

                if (!v0_1.equals("android.intent.action.PACKAGE_ADDED") && !v0_1.equals("android.intent.action.PACKAGE_REPLACED")) {
                    return;
                }

                Uri v0_3 = arg6.getData();
                if (v0_3 == null) {
                    return;
                }

                v0_1 = v0_3.getSchemeSpecificPart();
                if (android.support.design.a.v == null) {
                    return;
                }

                if (Logger.debug()) {
                    Logger.d("launcher_ad", "DownloadReceiver packageName = " + v0_1);
                }

                DownloadAdapterProxy.inst().handleAppInstalled(arg5, v0_1);
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }
    }
}

